#ifndef __INCLUDED_CBL_SMARTPTR_H__
#error "CBL_SmartPtr.hpp must not be used directly. Use CBL_SmartPtr.h instead."
#else
#ifndef __INCLUDED_CBL_SMARTPTR_HPP__
#define __INCLUDED_CBL_SMARTPTR_HPP__

template <typename TType>
CSmartPtr<TType>::CSmartPtr()
	: m_pObject(NULL)
{
}

// -------------------------------------------------------------------------------------

template <typename TType>
CSmartPtr<TType>::CSmartPtr(TType*& _rpObject)
{
    m_pObject = _rpObject;
    _rpObject = NULL;
}

// -------------------------------------------------------------------------------------

template <typename TType>
CSmartPtr<TType>::CSmartPtr(const CSmartPtr<TType>& _rCopy)
{
	// "move" constructors are not integrated in the current c++ standard, so
    // we need a const_cast here ...
    m_pObject = const_cast<CSmartPtr<TType>&>(_rCopy).Retain();
}

// -------------------------------------------------------------------------------------

template <typename TType>
template <typename TType2>
CSmartPtr<TType>::CSmartPtr(CSmartPtr<TType2>& _rCopy)
{
    m_pObject = static_cast<TType*>(_rCopy.Retain());
}

// -------------------------------------------------------------------------------------

template <typename TType>
CSmartPtr<TType>::~CSmartPtr()
{
    delete m_pObject;
}

// -------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE CSmartPtr<TType>& CB_INLINE_ATTR CSmartPtr<TType>::operator = (TType*& _rpNewObject)
{
    delete m_pObject;
    
    m_pObject = _rpNewObject;
    _rpNewObject = NULL;
    
    return *this;
}

// -------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE CSmartPtr<TType>& CB_INLINE_ATTR CSmartPtr<TType>::operator = (const CSmartPtr<TType>& _rCopy)
{
    delete m_pObject;
    m_pObject = _rCopy.m_pObject;
    const_cast<CSmartPtr&>(_rCopy).m_pObject = NULL;
    return *this;
}

// -------------------------------------------------------------------------------------

template <typename TType>
template <typename TType2>
CB_FORCEINLINE CSmartPtr<TType>& CB_INLINE_ATTR CSmartPtr<TType>::operator = (CSmartPtr<TType2>& _rCopy)
{
    delete m_pObject;
    m_pObject = static_cast<TType*>(_rCopy.m_pObject);
    _rCopy.m_pObject = NULL;
    return *this;
}

// -------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE TType* CB_INLINE_ATTR CSmartPtr<TType>::Retain()
{ 
    TType *pTemp = m_pObject; 
    m_pObject = NULL; 
    return pTemp;
}

#endif
#endif